public class immediatelyActivateHospital{

    String hosId = System.currentPageReference().getParameters().get('id');
    List<Hospital__c> target = [select id,approvalstatus__c,effectivedate__c from Hospital__c where Id =: System.currentPageReference().getParameters().get('id')];
    
    public Hospital__c hos {
        get{
            if (hos==null)
                if(target.size() > 0){
                    hos = target[0];
                }
                else
                    hos = null;
            return hos;
        }
        set;
    }
    
    public PageReference Submit() {
        if(hos.approvalstatus__c == '审批通过但未生效'){
            hos.effectivedate__c=date.today();
            hos.approvalstatus__c='审批通过';
            update hos;
        }
            return new ApexPages.StandardController(new Hospital__c(Id = hosId)).view();    
    }
    
    static testMethod void immediatelyActivateHospitalTest()
    {
        Hospital__c hos1 = new Hospital__c(Name = 'a',Nickname__c = 'a',Active__c = true, approvalstatus__c = '审批通过但未生效');
        insert hos1;
        
        immediatelyActivateHospital testcase = new immediatelyActivateHospital();
        testcase.target.add(hos1); 
        testcase.Submit();
        
    }
}